package LeetCode.leetcode454;

import java.util.HashMap;

public class Review1 {
    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        HashMap<Integer, Integer> map = new HashMap<>();
        int resCount = 0;
        for (int i : nums1) {
            //装到map中
            for (int j : nums2) {
                map.compute(i + j, (k, v) -> (v == null) ? 1 : v + 1);
            }
        }
        //从map中取出
        for (int i : nums3) {
            for (int j : nums4) {
                if (map.containsKey(-(i + j))) {
                    resCount += map.get(-(i + j));
                }
            }
        }
        return resCount;
    }
}
